import Vue from 'vue'
import VueRouter from 'vue-router'
// import RegisterPage from '@/views/Register.vue'
// import LoginPage from '@/views/Login.vue'
import Layout from '@/views/Layout.vue'
// import { getToken } from '@/utils/storage'

Vue.use(VueRouter)

const routes = [
  {
    path: '/register',
    // component: RegisterPage
    component: () => import('@/views/Register.vue')
  },
  {
    path: '/citylist',
    component: () => import('@/views/CitySelect.vue')
  },
  {
    path: '/map',
    component: () => import('@/views/MapFind.vue')
  },
  {
    path: '/login',
    // component: LoginPage
    component: () => import('@/views/Login.vue') // 路由懒加载写法
  },
  {
    path: '/fang',
    // component: LoginPage
    component: () => import('@/views/FangInfo.vue') // 路由懒加载写法
  },
  { path: '/detail', component: () => import('@/views/Detail.vue') },
  {
    path: '/',
    component: Layout,
    children: [
      { path: '/home', component: () => import('@/views/Article.vue') },
      { path: '/home/list', component: () => import('@/views/Collect.vue') },
      { path: '/homenews', component: () => import('@/views/Like.vue') },
      { path: '/home/profile', component: () => import('@/views/User.vue') }
    ]
  }
]

const router = new VueRouter({
  routes
})

// const whiteList = ['/register', '/login']
// router.beforeEach((to, from, next) => {
//   const token = getToken()
//   if (token) {
//     next()
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })

export default router
